package com.yaorange.guild.association.controller;

import com.github.pagehelper.PageInfo;
import com.yaorange.guild.association.entity.BsAssociationCouncil;
import com.yaorange.guild.association.service.BsAssociationCouncilService;
import com.yaorange.response.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 协会理事会成员信息Controller
 */
@RestController
@RequestMapping("/bsAssociationCouncils")
public class BsAssociationCouncilController {

    @Autowired
    private BsAssociationCouncilService bsAssociationCouncilService;

    /**
     * 插入协会理事会成员信息
     */
    @PostMapping
    public Result insert(@RequestBody BsAssociationCouncil council) {
        council.setDelFlag(0);
        int result = bsAssociationCouncilService.insert(council);
        return result > 0 ? Result.success("插入成功") : Result.fail("插入失败");
    }

    /**
     * 根据主键更新协会理事会成员信息
     */
    @PutMapping("/{id}")
    public Result updateById(@PathVariable Long id, @RequestBody BsAssociationCouncil council) {
        council.setId(id);
        int result = bsAssociationCouncilService.updateById(council);
        return result > 0 ? Result.success("更新成功") : Result.fail("更新失败");
    }

    /**
     * 根据主键删除协会理事会成员信息
     */
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Long id) {
        BsAssociationCouncil bsAssociationCouncil = new BsAssociationCouncil();
        bsAssociationCouncil.setId(id);
        bsAssociationCouncil.setDelFlag(1);
        int result = bsAssociationCouncilService.updateById(bsAssociationCouncil);
        return result > 0 ? Result.success("删除成功") : Result.fail("删除失败");
    }

    /**
     * 根据主键查询协会理事会成员信息
     */
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Long id) {
        BsAssociationCouncil council = bsAssociationCouncilService.selectById(id);
        return council != null ? Result.success(council) : Result.fail("未找到对应记录");
    }

    /**
     * 查询所有协会理事会成员信息
     */
    @GetMapping
    public Result selectAll(BsAssociationCouncil query) {
        List<BsAssociationCouncil> list = bsAssociationCouncilService.selectAll(query);
        return Result.success(list);
    }

    /**
     * 分页查询协会理事会成员信息
     */
    @GetMapping("/page")
    public Result selectPage(BsAssociationCouncil query, @RequestParam(defaultValue = "1") Integer pageNo, @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<BsAssociationCouncil> pageInfo = bsAssociationCouncilService.selectPage(query, pageNo, pageSize);
        return Result.success(pageInfo);
    }
}
